home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CASample / CAS_HelpBalloon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  3.6 KB  |  156 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAS_HelpBalloon.c
  3.  
  4.     Contains:    balloon help code.
  5.  
  6.     Written by:    David H Nelson
  7.  
  8.     Copyright © 1993-1995 ComponentWorks, All rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      9/13/95    TWB        Comment out unnecessary include of CALib. 
  13.          <1>     11/20/93    DHN        Created.
  14. */
  15.  
  16. #include <Balloons.h>
  17. #include "CAS_HelpBalloon.h"
  18. #include "CAS_Globals.h"
  19. #include "CAS_Doc.h"
  20.  
  21. //----------------------------------------------------------------------
  22.  
  23. RgnHandle    hotRgn = nil;
  24.  
  25. //----------------------------------------------------------------------
  26.  
  27. void hideBalloons( WindowPtr theWindow )
  28. {
  29.     // if balloon help is not on, get out.
  30.     if (!HMGetBalloons())
  31.         return;
  32.  
  33.     // if the hotRgn hasn't been allocated, create it.
  34.     if (!hotRgn)
  35.         hotRgn = NewRgn();
  36.  
  37.     // if our existing balloon hotRgn is not empty…
  38.     if (!EmptyRgn(hotRgn))
  39.     {
  40.         // if there is a balloon showing, hide it.
  41.         if (HMIsBalloon())
  42.             HMRemoveBalloon();        // hide the balloon.
  43.  
  44.         SetRectRgn(hotRgn,0,0,0,0);    // clear the hotRgn
  45.     }
  46. }
  47.  
  48. //----------------------------------------------------------------------
  49.  
  50. void doBalloonHelp( WindowPtr theWindow )
  51. {
  52.     short                index;
  53.     Rect                hotRect;
  54.     Rect                growRect;
  55.     Point                aPoint;
  56.     HMMessageRecord        helpMsg;
  57.     HMStringResType        *hmString;
  58.     OSErr                theErr;
  59.     DocPtr            theDoc;
  60.  
  61.     // if balloon help is not on, get out.
  62.     if (!HMGetBalloons())
  63.         return;
  64.  
  65.     // if the hotRgn hasn't been allocated, create it.
  66.     if (!hotRgn)
  67.         hotRgn = NewRgn();
  68.  
  69.     // if there's no window don't do anything
  70.     if (!theWindow)
  71.         return;
  72.  
  73.     // if the window is not hilited, our GetMouse will return the global mouse position
  74.     // which will screw up the rest of our code below, so don't do anything.
  75.     if (!((WindowPeek) theWindow)->hilited)
  76.         return;
  77.  
  78.     theDoc = (DocPtr) GetWRefCon(theWindow);
  79.  
  80.     GetMouse( &aPoint );
  81.  
  82.     // if our existing balloon hotRgn is not empty…
  83.     if (!EmptyRgn(hotRgn))
  84.     {
  85.         // if we're still in the hotRgn, get out.
  86.         if (PtInRgn( aPoint, hotRgn ))
  87.             return;
  88.  
  89.         // we're not in the hotRgn, so
  90.         // if there is a balloon showing, hide it, clear the hotRgn, and get out.
  91.         if (HMIsBalloon())
  92.         {
  93.             HMRemoveBalloon();        // hide the balloon.
  94.             SetRectRgn(hotRgn,0,0,0,0);    // clear the hotRgn
  95.             return;
  96.         }
  97.     }
  98.  
  99.     growRect = theWindow->portRect;
  100.     growRect.left = growRect.right - SBARWIDTH + 1;
  101.     growRect.top = growRect.bottom - SBARWIDTH + 1;
  102.  
  103.     if (PtInRect( aPoint, &theDoc->hScrollBarRect ))
  104.     {
  105.         index = 1;
  106.         RectRgn(hotRgn, &theDoc->hScrollBarRect);
  107.     }
  108.     else if (PtInRect( aPoint, &theDoc->vScrollBarRect ))
  109.     {
  110.         index = 2;
  111.         RectRgn(hotRgn, &theDoc->vScrollBarRect);
  112.     }
  113.     else if (PtInRect( aPoint, &growRect))
  114.     {
  115.         index = 3;
  116.         RectRgn(hotRgn, &growRect);
  117.     }
  118.     else if (PtInRect( aPoint, &theDoc->contentRect ))
  119.     {
  120.         index = 4;
  121.         RectRgn(hotRgn, &theDoc->contentRect);
  122.     }
  123.     else
  124.     {
  125.         SetRectRgn(hotRgn,0,0,0,0);    // clear the hotRgn
  126.         return;
  127.     }
  128.  
  129.     /******************************************************************/
  130.     /* Grab the string from the 'STR#' resource for the help message. */
  131.     /******************************************************************/
  132.  
  133.     hotRect = (**hotRgn).rgnBBox;
  134.  
  135.     LocalToGlobal( &topLeft( hotRect ) );
  136.     LocalToGlobal( &botRight( hotRect ) );
  137.  
  138. //    SetPt( &aPoint, ((hotRect.right - hotRect.left) >> 1) + hotRect.left,
  139. //                    ((hotRect.bottom - hotRect.top) >> 1) + hotRect.top );
  140.     LocalToGlobal( &aPoint );
  141.  
  142.     helpMsg.hmmHelpType = khmmStringRes;
  143.  
  144.     hmString = (HMStringResType*)&helpMsg.u;
  145.  
  146.     (*hmString).hmmResID = kMainWindowHelpStrings;
  147.     (*hmString).hmmIndex = index;
  148.  
  149.     theErr = HMShowBalloon( &helpMsg, aPoint, &hotRect, nil, 0, 0, kHMSaveBitsWindow );
  150.  
  151.     // if there were any errors (like the cursor constantly moving) start over.
  152.     if (theErr != noErr)
  153.         SetRectRgn(hotRgn,0,0,0,0);
  154. }
  155.  
  156.